package com.whmnx.main.ui.adapter;

import android.content.Context;
import android.view.View;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.whmnx.base.bean.LoginBean;
import com.whmnx.base.bean.VideoListBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.base.utils.ImageUtil;
import com.whmnx.base.utils.UItils;
import com.whmnx.base.view.CommonDialog2;
import com.whmnx.main.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author : huang
 * date   : 2020/10/14 0014 17:00
 * version: 1.0
 * @author Administrator
 */
public class VedioAdapter3 extends CommonRecyclerAdapter<VideoListBean> {
    Context context;
    public VedioAdapter3(Context context) {
        super(context, R.layout.item_work2);
        this.context = context;
    }


    @Override
    public void onUpdate(BaseAdapterHelper helper, VideoListBean item, int position) {
        helper.setText(R.id.tv_num,item.playNum);
        ImageUtil.setImage(helper.getView(R.id.iv_vedio), item.getWork_Vidoe());


        UItils.loadVideoScreenshot(context,item.getWork_Vidoe(),helper.getView(R.id.iv_vedio));

        helper.setVisible(R.id.iv_cel, View.INVISIBLE);
        Constants.alreadyLikeList.add(item.getIsLike() == 1);



        helper.setOnClickListener(R.id.iv_cel, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s2 = "是否删除该视频";
                new CommonDialog2(context, R.style.dialog, s2,"", (dialog, confirm) -> {
                    if (confirm) {
                        Map<String, Object> params = new HashMap<>();
                        List<String> list = new ArrayList<>();
                        list.add(item.getWork_Id());
                        params.put("",list);
                        HttpClient.post(context, Constants.DELETE3, params,new CallBack<LoginBean>() {
                            @Override
                            public void onSuccess(LoginBean result) {
                                //  viewModel.observableList.remove(videoBean);
                              //  viewModel.deleteItem(WorkItemViewModel.this);
                                getData().remove(position);
                                notifyItemRemoved(position);
                                if (position != getData().size()) {
                                    notifyItemRangeChanged(position, getData().size() - position);
                                }
                            }
                        });
                    }
                    dialog.dismiss();
                }).show();
            }
        });
    }
}
